import re
from django.contrib import admin
from api import models
from django.utils.safestring import mark_safe

class DeviceAdmin(admin.ModelAdmin):
    list_display = ["id", "did", "dy_account", "phone_model"]


admin.site.register(models.Device, DeviceAdmin)


class TaskAdmin(admin.ModelAdmin):

    def short_address(self, obj):
        # 5- #在抖音，记录美好生活#【兰兰形体有氧运动健身】正在直播，来和我一起支持Ta吧。复制下方链接，打开【抖音】，直接观看直播！ https://v.douyin.com/i691mf8E/ 2@2.com :0pm
        return re.findall(".*?【(.+?)】.*", obj.address)

    short_address.__name__ = "短标题"

    def display_text(self, obj):
        return mark_safe(f"<pre>{obj.text}</pre>")

    display_text.__name__ = "评论"
    list_display = ["id", "device", "short_address","display_text", "loop_count", 'status']


admin.site.register(models.Task, TaskAdmin)
